<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./vue/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="demo">
        <input value="" placeholder="input A" v-model="strA" /><br>
        <input value="" placeholder="input B" v-model="strB" /><br>
        <input value="" placeholder="input C which couldn't edit data" :value="strC" /><br>
        <span :style="style">{{combind}}</span>
    </div>

    <script>
        var vm = new Vue({
            el: "#demo",
            data: {
                // set style
                style: "color:red;",
                // set properties
                combind: "default",
                strA: "",
                strB: "",
                strC: "",
            },
            watch: {
                //下为简写，无法配置深度监视
                strA(newValue, oldValue) {
                    console.log("A changed! " + newValue + " " + oldValue);
                    console.log("A now is " + this.strA);
                    this.combind = newValue + "-" + this.strB;
                },

                //下标准形式
                strB: {
                    //配置深度监视，非必要项
                    deep: true,
                    //配置初始化，非必要项
                    immediate: true,
                    handler(newValue, oldValue) {
                        console.log("B changed! " + newValue + " " + oldValue);
                        console.log("B now is " + this.strB);
                        this.combind = this.strA + "-" + newValue;
                    }
                },

                //监视strC
                strC() {
                    console.log("CCCCC!");
                }
            },
        });
    </script>
</body>

</html>